<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<button>按我加一</button>
<button id="btn">按我减一</button>
<script>
    var elh1 = document.getElementsByTagName("h1")[0];
    var elbtn = document.getElementsByTagName("button")[0];
    var elbtn2 = document.getElementById("btn");
    var num = 0;
    elbtn.onclick = function (ev) {
        num++;
        elh1.innerHTML = num;
    }
    elbtn2.onclick = function (ev) {
        num--;
        elh1.innerHTML = num;
    }
</script>
</body>
</html>